package com.example.cash.craft.dao.persist.repository.impl;

import com.example.cash.craft.dao.persist.mapper.RewardPointsLogMapper;
import com.example.cash.craft.dao.persist.repository.IRewardPointsLogRepository;
import com.example.cash.craft.pojo.entity.RewardPointsLog;
import com.example.cash.craft.pojo.vo.PageData;
import com.example.cash.craft.pojo.vo.RewardPointsLogVO;
import com.example.cash.craft.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RewardPointsLogRepositoryImpl implements IRewardPointsLogRepository {

    @Autowired
    private RewardPointsLogMapper rewardPointsLogMapper;

    @Override
    public int insert(RewardPointsLog rewardPointsLog) {
        return rewardPointsLogMapper.insert(rewardPointsLog);
    }

    @Override
    public int sumByUserId(Long userId) {
        return rewardPointsLogMapper.sumByUserId(userId);
    }

    @Override
    public PageData<RewardPointsLogVO> listByUserId(Long userId, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RewardPointsLogVO> list = rewardPointsLogMapper.listByUserId(userId);
        PageInfo<RewardPointsLogVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

}
